package com.ktgj.service.controller;

import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.web.page.TableDataInfo;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.domain.KtserviceContractActivitycodebatch;
import com.ktgj.service.service.IKtserviceContractActivitycodebatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * 码批次Controller
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@ControllerAdvice
@RestController
@RequestMapping("/activitycodebatch")
public class KtserviceContractActivitycodebatchController extends BaseController
{
    @Autowired
    private IKtserviceContractActivitycodebatchService KtserviceContractActivitycodebatchService;

    /**
     * 查询码批次列表
     */
    //@PreAuthorize(hasPermi = "service:activitycodebatch:list")
    @GetMapping("/list")
    public TableDataInfo list(KtserviceContractActivitycodebatch KtserviceContractActivitycodebatch)
    {
        startPage();
        List<KtserviceContractActivitycodebatch> list = KtserviceContractActivitycodebatchService.selectKtserviceContractActivitycodebatchList(KtserviceContractActivitycodebatch);
        return getDataTable(list);
    }

    /**
     * 导出码批次列表
     */
    @PreAuthorize(hasPermi = "service:activitycodebatch:export")
    @Log(title = "码批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KtserviceContractActivitycodebatch KtserviceContractActivitycodebatch) throws IOException
    {
        List<KtserviceContractActivitycodebatch> list = KtserviceContractActivitycodebatchService.selectKtserviceContractActivitycodebatchList(KtserviceContractActivitycodebatch);
        ExcelUtil<KtserviceContractActivitycodebatch> util = new ExcelUtil<KtserviceContractActivitycodebatch>(KtserviceContractActivitycodebatch.class);
        util.exportExcel(response, list, "码批次数据");
    }

    /**
     * 获取码批次详细信息
     */
    @PreAuthorize(hasPermi = "service:activitycodebatch:query")
    @GetMapping(value = "/{activityCodeBatchId}")
    public AjaxResult getInfo(@PathVariable("activityCodeBatchId") Long activityCodeBatchId)
    {
        return AjaxResult.success(KtserviceContractActivitycodebatchService.selectKtserviceContractActivitycodebatchById(activityCodeBatchId));
    }

    /**
     * 新增码批次
     */
    //@PreAuthorize(hasPermi = "service:activitycodebatch:add")
    @Log(title = "码批次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KtserviceContractActivitycodebatch KtserviceContractActivitycodebatch)
    {
        return toAjax(KtserviceContractActivitycodebatchService.insertKtserviceContractActivitycodebatch(KtserviceContractActivitycodebatch));
    }

    /**
     * 修改码批次*/
    @PreAuthorize(hasPermi = "service:activitycodebatch:edit")
    @Log(title = "码批次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KtserviceContractActivitycodebatch KtserviceContractActivitycodebatch)
    {
        return toAjax(KtserviceContractActivitycodebatchService.updateKtserviceContractActivitycodebatch(KtserviceContractActivitycodebatch));
    }

    /**
     * 删除码批次*/
    @PreAuthorize(hasPermi = "service:activitycodebatch:remove")
    @Log(title = "码批次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityCodeBatchIds}")
    public AjaxResult remove(@PathVariable Long[] activityCodeBatchIds)
    {
        return toAjax(KtserviceContractActivitycodebatchService.deleteKtserviceContractActivitycodebatchByIds(activityCodeBatchIds));
    }

    /**
     *活动码续码
     * @param bathName 码批次名称
     * @param generateNumber 续码数
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @Log(title = "活动码续码")
    @PostMapping("/addActivityCodeBathContinuation")
    public AjaxResult addActivityCodeBathContinuation(@RequestParam("bathName") String bathName,
                                                      @RequestParam("generateNumber") Long generateNumber,
                                                      @RequestParam("startDate") Date startDate,
                                                      @RequestParam("endDate") Date endDate){

        return toAjax(KtserviceContractActivitycodebatchService.
                addActivityCodeBathContinuation(bathName,generateNumber,startDate,endDate));
    }
}
